package com.itany.book.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itany.mapper.PermissionMapper;
import com.itany.pojo.Permission;
import com.itany.service.PermissionService;
import com.itany.vo.UserPermissionVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Author：汤小洋
 * Date：2019-09-24 上午9:38
 * Description：<描述>
 */
@Service
@Transactional(propagation = Propagation.REQUIRED,rollbackFor = Throwable.class)
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Transactional(readOnly = true)
    public PageInfo<Permission> findAllBook(Integer page, Integer rows, Permission permission) {
        PageHelper.startPage(page, rows);
     List<Permission> permissions= permissionMapper.selectAll(permission);
     PageInfo<Permission> info = new PageInfo<Permission>(permissions);


        return info;
    }

    @Transactional(readOnly = true)
    public List<Permission> findAllParent() {

        List<Permission> permissions=  permissionMapper.selectAllParent();

        return permissions;
    }



    public void modifyPermission(Permission permission) {

        permissionMapper.updatePermission(permission);

    }


    @Transactional(readOnly = true)
    public List<Permission> findPermission() {
        List<Permission> permissions=permissionMapper.selectAllByParentId();

        return permissions;
    }

    public List<UserPermissionVo> findPermissionById(Integer id) {

        List<UserPermissionVo> permissions = permissionMapper.selectAllByParentIdAndId(id);

        return permissions;
    }
}